package com.his_voice.voice.controller;

import com.his_voice.voice.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.*;

@RestController
@RequestMapping("/api/voice")
public class OrderVoiceController {

    @PostMapping("uploadFile")
    public ResponseResult uploadFile(MultipartFile file) throws IOException {
        InputStream inputStream = file.getInputStream();
        if (file.getSize() <= 0) {
            return new ResponseResult(2, "success", "文件长度不能为空");
        }
        System.out.println(121);
        String filePath = "/Users/michaelwu/redmill/zvoice/a.txt";
        if (!new File(filePath).exists()) {
            new File(filePath).createNewFile();
        }
        System.out.println(3333);
        OutputStream outputStream = new FileOutputStream(filePath);
        for (int i = 0; i < file.getSize(); i++) {
            char c = (char) inputStream.read();
            outputStream.write(c);
            System.out.println(4444);
        }
        inputStream.close();
        outputStream.close();

        return new ResponseResult(1, "success", "");
    }
}